import express from "express";
import { StatisticsService } from "../../services/school/statisticsService.mjs";

const router = express.Router();

/**
 * @swagger
 * /api/schools/statistics/major-hierarchy/{level}/{code}:
 *   get:
 *     summary: 获取专业层级数据
 *     description: 获取专业层级数据
 *     responses:
 *       200:
 *         description: 专业层级数据获取成功
 */
// 获取专业层级数据
router.get("/major-hierarchy/:level/:code", async (req, res) => {
  try {
    const { level, code } = req.params;
    const result = await StatisticsService.getMajorHierarchy(level, code);
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

/**
 * @swagger
 * /api/school/statistics/major-distribution:
 *   get:
 *     summary: 获取专业分布数据
 *     description: 获取专业分布数据
 *     responses:
 *       200:
 *         description: 专业分布数据获取成功
 */
router.get("/major-distribution", async (req, res) => {
  try {
    const result = await StatisticsService.getMajorDistribution();
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

/**
 * @swagger
 * /api/schools/statistics/employment-trend:
 *   get:
 *     summary: 获取就业趋势数据
 *     description: 获取就业趋势数据
 *     responses:
 *       200:
 *         description: 就业趋势数据获取成功
 */
router.get("/employment-trend", async (req, res) => {
  try {
    const result = await StatisticsService.getEmploymentTrend();
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

/**
 * @swagger
 * /api/schools/statistics/salary-comparison:
 *   get:
 *     summary: 获取收入水平比较数据
 *     description: 获取收入水平比较数据
 *     responses:
 *       200:
 *         description: 收入水平比较数据获取成功
 */
router.get("/salary-comparison", async (req, res) => {
  try {
    const result = await StatisticsService.getSalaryComparison();
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

/**
 * @swagger
 * /api/schools/statistics/number-statistics:
 *   get:
 *     summary: 获取统计数据概览
 *     description: 获取统计数据概览
 *     responses:
 *       200:
 *         description: 统计数据概览获取成功
 */
router.get("/number-statistics", async (req, res) => {
  try {
    const result = await StatisticsService.getNumberStatistics();
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

/**
 * @swagger
 * /api/schools/statistics/major-tree:
 *   get:
 *     summary: 获取专业树状结构
 *     description: 获取完整的专业层级树状结构
 *     responses:
 *       200:
 *         description: 成功获取专业树状结构
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 tree:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       key:
 *                         type: string
 *                       title:
 *                         type: string
 *                       value:
 *                         type: number
 *                       children:
 *                         type: array
 *                 lastUpdated:
 *                   type: string
 *                   format: date-time
 *                 summary:
 *                   type: object
 *                   properties:
 *                     level1Count:
 *                       type: number
 *                     level2Count:
 *                       type: number
 *                     level3Count:
 *                       type: number
 *       500:
 *         description: 服务器错误
 */
router.get("/major-tree", async (req, res) => {
  try {
    const result = await StatisticsService.getMajorTree();
    res.json(result);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

export default router;
